package codeTop;

public class q129 {
    public int sumNumbers(TreeNode root) {
        if (root == null) {
            return 0;
        }
        dfs(root,0);
        return res;
    }

    int res = 0;
    private void dfs(TreeNode node, int num) {
        num = num*10+node.val;
        if (node.left == null && node.right == null) {
            res+=num;
            return;
        }
        if (node.left != null) {
            dfs(node.left,num);
        }
        if (node.right != null) {
            dfs(node.right,num);
        }
    }
}
